package com.jiufen.Aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 *
 */
@Component
//@Aspect   //交由LogAspect 统一记录
@Slf4j
public class RecordTimeAspect {

    //生效范围
    @Around("execution(* com.jiufen.Service.impl.*.*(..))")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        //记录开始时间
        Long begin = System.currentTimeMillis();

        //执行原始方法
        Object result  = joinPoint.proceed();

        //记录结束时间
        Long end = System.currentTimeMillis();
        log.info("方法名：{}---方法执行耗时：{}ms",joinPoint.getSignature(),end-begin);

        //返回原始方法结果
        return  result;
    }

}
